#include <stdio.h>

int main()
{
    int result = -1;

    result = (2 - 1 ? 3 ? 4 : 5 : 6 ? 7 : 8);
    printf("result = %d\n", result);        // 4

    result = (1 == 2 - 1 ? 3 ? 4 : 5 : 6 ? 7 : 8);
    printf("result = %d\n", result);        // 4

    result = (2 - 2 ? 3 ? 4 : 5 : 6 ? 7 : 8);
    printf("result = %d\n", result);        // 7

    return 0;
}

/*
0000000000001149 <main>:
    1149:	f3 0f 1e fa          	endbr64 
    114d:	55                   	push   %rbp
    114e:	48 89 e5             	mov    %rsp,%rbp
    1151:	48 83 ec 10          	sub    $0x10,%rsp
    1155:	c7 45 fc ff ff ff ff 	movl   $0xffffffff,-0x4(%rbp)
    115c:	c7 45 fc 04 00 00 00 	movl   $0x4,-0x4(%rbp)
    1163:	8b 45 fc             	mov    -0x4(%rbp),%eax
    1166:	89 c6                	mov    %eax,%esi
    1168:	48 8d 3d 95 0e 00 00 	lea    0xe95(%rip),%rdi        # 2004 <_IO_stdin_used+0x4>
    116f:	b8 00 00 00 00       	mov    $0x0,%eax
    1174:	e8 d7 fe ff ff       	callq  1050 <printf@plt>
    1179:	c7 45 fc 04 00 00 00 	movl   $0x4,-0x4(%rbp)
    1180:	8b 45 fc             	mov    -0x4(%rbp),%eax
    1183:	89 c6                	mov    %eax,%esi
    1185:	48 8d 3d 78 0e 00 00 	lea    0xe78(%rip),%rdi        # 2004 <_IO_stdin_used+0x4>
    118c:	b8 00 00 00 00       	mov    $0x0,%eax
    1191:	e8 ba fe ff ff       	callq  1050 <printf@plt>
    1196:	b8 00 00 00 00       	mov    $0x0,%eax
    119b:	c9                   	leaveq 
    119c:	c3                   	retq   
    119d:	0f 1f 00             	nopl   (%rax)
*/

#if 0

(1 == 2 - 1 ? 3 ? 4 : 5 : 6 ? 7 : 8)

首先需要搞清楚运算符优先级和结合方式。以上表达式中减号(-)的优先级最高，其次是双等号(==)，
且条件运行符是由右向左。运算流程如下。

(1 == 2 - 1 ? 3 ? 4 : 5 : 6 ? 7 : 8)
= (1 == 1 ? 3 ? 4 : 5 : 6 ? 7 : 8)   # 先减
= (1 ? 3 ? 4 : 5 : 6 ? 7 : 8)        # 再双等，1==1，取1
= (1 ? 3 ? 4 : 5 : 7)                # 6 ? 7 : 8  ==> 7
= (1 ? 4 : 7)                        # 3 ? 4 : 5   ==> 4
= 4

#endif